package com.itheima.controller;

import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


//异常处理器
@RestControllerAdvice
public class ProjectExceptionAdvice {


    //自定义异常
    @ExceptionHandler(SystemException.class)
    public Result doSystemExceptionException(SystemException e){
        //记录日记
        //发送消息给运营
        //发送邮件给开发人员，e对象发送给开发人员
        return new Result(e.getCode(),null,e.getMessage());
    }

    //自定义异常
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessExceptionException(BusinessException e){

        return new Result(e.getCode(),null,e.getMessage());
    }




    @ExceptionHandler(Exception.class)//指定异常
    public Result doException(Exception e){//参数 ：被抓住的异常

        //记录日记
        //发送消息给运营
        //发送邮件给开发人员，e对象发送给开发人员
        System.out.println("嘿嘿，异常你哪里跑");

        return new Result(Code.SYSTEM_UNKNOW_ERR,null,"系统繁忙，请稍后再试！");
    }



}
